import { defineStore } from 'pinia'

export interface GlobalErrorProps {
  status: boolean
  message?: string
}

export interface GlobalStatusProps {
  error: GlobalErrorProps
  loading: boolean
}

// store 名称 global
export const useGlobalStore = defineStore('global', {
  // 状态
  state: (): GlobalStatusProps => {
    return {
      error: { status: false },
      loading: false
    }
  },
  actions: {
    setLoading(status: boolean) {
      this.loading = status
    },
    setError(e: GlobalErrorProps) {
      this.error = e
    }
  }
})

export type GlobalStoreType = ReturnType<typeof useGlobalStore>
